/****************************************************
	文件：PlayerEntity.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/5/31 21:46:28
	功能：玩家 实体
*****************************************************/

using System.Collections.Generic;
using HTUtility;
using UnityEngine;

namespace AIModule.Utility.Example
{
    public class PlayerEntity : EntityBase
    {
        public PlayerEntity(string name)
        {
            mCommandQue = new Queue<CommandBase>();
            Model = new PlayerModel
            {
                Name = name,
                Entity = this,
                MaxHp = new ReactiveProperty<int>(100),
                Hp = new ReactiveProperty<int>(100),
                Atk = new ReactiveProperty<int>(15),
                AtkRangeRadius = new ReactiveProperty<int>(7),
                Def = new ReactiveProperty<int>(5),
                CurativePotionNum = new ReactiveProperty<int>(3),
                Active = new ReactiveProperty<bool>(true),
            };
            BB = new BlackboardItem
            {
                SelfModel = Model,
            };
            SubscribeReactiveProperty();
        }

        private void SubscribeReactiveProperty()
        {
            Model.Hp.Subscribe(hp =>
            {
                if (hp > Model.MaxHp.Value)
                    Model.Hp.Value = Model.MaxHp.Value;
                if (hp < 0)
                {
                    Model.Hp.Value = 0;
                    Model.Active.Value = false;
                    GameRoot.Instance.GameOver.Value = true;
                    Debug.LogFormat("{0} 已经死亡，游戏失败！", Model.Name);
                }
            });
        }
        /// <summary>
        /// 重置属性、状态
        /// </summary>
        public void Reset()
        {
            mCommandQue.Clear();
            Model.Hp.Value = 100;
            Model.CurativePotionNum.Value = 3;
        }
    }
}